package cn.liangent.travlib;

import static cn.liangent.travlib.util.Utilities.*;
import HTTPClient.*;

public class Structure extends Building {
	
	public Structure(Village village, int id) {
		super(village, id);
		if (id < 19 || id > 40) {
			throw new IllegalArgumentException();
		}
	}

	public void demolish() throws IOException, HttpException, AuthenticationException, BadPageException, CannotWorkException {
		String mb = getVillage().httpGet("/build.php?gid=15");
		if (!mb.contains("<form action=\"build.php\" method=\"POST\">")) {
			throw new CannotWorkException("cannot demolish");
		}
		NVPair[] param = new NVPair[] {
			new NVPair("gid", "15"),
			new NVPair("a", Integer.toString(getVillage().getNewdid())),
			new NVPair("abriss", Integer.toString(getId())),
			new NVPair("ok", getVillage().getClient().getUser().getString("demolish"));
		};
		getVillage().httpPost("/build.php", param);
	}
}
